package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TMarryInfo;
import com.ruoyi.marry.service.ITMarryInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 婚礼邀请Controller
 *
 * @author user_marry
 * @date 2020-11-19
 */
@RestController
@RequestMapping("/marry/marryInfo")
public class TMarryInfoController extends BaseController {

    @Autowired
    private ITMarryInfoService TMarryInfoService;

    /**
     * 查询婚礼邀请列表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMarryInfo tMarryInfo) {
        startPage();
        List<TMarryInfo> list = TMarryInfoService.selectTMarryInfoList(tMarryInfo);
        return getDataTable(list);
    }

    /**
     * 查询婚礼邀请(包含恋人信息)列表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryInfo:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll() {
        startPage();
        List<TMarryInfo> list = TMarryInfoService.selectTMarryInfoListAll();
        return getDataTable(list);
    }

    /**
     * 导出婚礼邀请列表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryInfo:export')")
    @Log(title = "婚礼邀请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMarryInfo tMarryInfo) {
        List<TMarryInfo> list = TMarryInfoService.selectTMarryInfoList(tMarryInfo);
        ExcelUtil<TMarryInfo> util = new ExcelUtil<TMarryInfo>(TMarryInfo.class);
        return util.exportExcel(list, "marrySetting");
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:marryInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(TMarryInfoService.selectTMarryInfoById(id));
    }

    /**
     * 新增保存婚礼邀请
     */
    @PreAuthorize("@ss.hasPermi('marry:marryInfo:add')")
    @Log(title = "婚礼邀请", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TMarryInfo tMarryInfo) {
        return toAjax(TMarryInfoService.insertTMarryInfo(tMarryInfo));
    }

    /**
     * 修改婚礼邀请
     */
    @PreAuthorize("@ss.hasPermi('marry:marryInfo:edit')")
    @Log(title = "婚礼邀请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMarryInfo tMarryInfo) {
        return toAjax(TMarryInfoService.updateTMarryInfo(tMarryInfo));
    }

    /**
     * 删除婚礼邀请
     */
    @PreAuthorize("@ss.hasPermi('marry:marryInfo:remove')")
    @Log(title = "婚礼邀请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(TMarryInfoService.deleteTMarryInfoByIds(ids));
    }
}
